window.onload=function(){
    axios.defaults.withCredentials = true;
    //获取用户信息
    let name=``
    axios.get('https://elm.cangdu.org/v1/user').then(res => {
        console.log(res);
        //用户名
        
      
          //修改用户名
   $('.kh_username').click(function(){
    window.location.href='/pages/username&userpic/username.html'
})
//获取修改后的用户名

let newname=window.localStorage.getItem('newname')
console.log(newname);
if(newname.length==0){
    $('#kh_usercount').html(res.data.username)
}
else{
    $('#kh_usercount').html(newname)
}
$('.kh_tosousuo').click(function(){
    if(newname.length>0){
        window.location.href=`/pages/my/my.html?newname=${newname}`
    }else if(newname.length==0){
        window.location.href=`/pages/my/my.html?newname=${res.data.username}`
    }
    
})
     
        //头像
     $('#kh_userimg').attr('src',`//elm.cangdu.org/img/${res.data.avatar}`)
    })
    console.log(name);

    //退出登录
    $('#kh_quit').click(function(){
        Toast('warning','你是否要退出');
        $('.kh_btu').click(function(){
            axios.get('https://elm.cangdu.org/v2/signout').then(res => {
                console.log(res);
            })
            window.location.href='/pages/my/my.html'
        })
    })
    //修改密码
    $('.kh_password').click(function(){
        window.location.href='/pages/forget/forget.html'
    })
    //绑定手机
    $('.kh_phone').click(function(){
        console.log(1);
        Toast('warning','请在手机APP中设置');
    })
    //收货地址
    $('.kh_address').click(function(){
        window.location.href='/pages/address/address.html'
    })
    //修改头像
    $('.kh_uesrpic').click(function(){
        Toast('fail','更换头像失败');
    })

    
 
    
    

}